package com.redis.data.seckillshopping.enums;

import com.redis.data.seckillshopping.service.ConsumerService;
import com.redis.data.seckillshopping.service.GoodsOrderService;
import com.redis.data.seckillshopping.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 哲思小辉
 * @version 1.0.0
 * @ClassName Operation.java
 * @Description 使用枚举来封装调用
 * @Param
 * @createTime 2020年04月03日 10:28:00
 */
public enum Operation {

    GOODSORDER {
        @Override
        public Object getId(int id) {
            return Service.goodsOrderService.queryById(id);
        }
    },

    CONSUMER {
        @Override
        public Object getId(int id) {
            return Service.consumerService.queryById(id);
        }
    },

    GOODS {
        @Override
        public Object getId(int id) {
            return Service.goodsService.queryById(id);
        }
    };

    Operation() {
    }

    @Component
    private static class Service {

        private static GoodsOrderService goodsOrderService;

        private static GoodsService goodsService;

        private static ConsumerService consumerService;

        @Autowired
        public void setGoodsOrderService(GoodsOrderService goodsOrderService) {
            Service.goodsOrderService = goodsOrderService;
        }

        @Autowired
        public void setGoodsService(GoodsService goodsService) {
            Service.goodsService = goodsService;
        }

        @Autowired
        public void setConsumerService(ConsumerService consumerService) {
            Service.consumerService = consumerService;
        }

    }

    public abstract Object getId(int id);

}
